/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.sysdance.aplicativo.visao.tela;

import java.awt.Window;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import org.sysdance.aplicativo.modelo.Curso;
import org.sysdance.aplicativo.servico.SCurso;
import org.sysdance.aplicativo.util.visao.JanelaDialogo;

/**
 *
 * @author gocards
 */
public class TelaCurso extends JanelaDialogo {

    final Curso curso = new Curso();

    /**
     * Creates new form TelaCurso
     */
    public TelaCurso(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        this.setTitle("SysDance - Curso:");
        initComponents();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jblIdadeMinima = new javax.swing.JPanel();
        jblNomedoCurso = new javax.swing.JLabel();
        tfNomeCurso = new javax.swing.JTextField();
        jblIdadeMinimaCurso = new javax.swing.JLabel();
        tfIdadeMinima = new javax.swing.JTextField();
        jblTempoCurso = new javax.swing.JLabel();
        tfTempoDoCurso = new javax.swing.JTextField();
        jblValorCurso = new javax.swing.JLabel();
        tfValorDoCurso = new javax.swing.JTextField();
        btnSairCurso = new javax.swing.JButton();
        btnSalvarCurso = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jblIdadeMinima.setBorder(javax.swing.BorderFactory.createTitledBorder("Curso:"));

        jblNomedoCurso.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jblNomedoCurso.setText("Nome do curso:");

        jblIdadeMinimaCurso.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jblIdadeMinimaCurso.setText("Idade Mínima:");

        jblTempoCurso.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jblTempoCurso.setText("Tempo do Curso:");

        tfTempoDoCurso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfTempoDoCursoActionPerformed(evt);
            }
        });

        jblValorCurso.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jblValorCurso.setText("Valor:");

        btnSairCurso.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        btnSairCurso.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sysdance/aplicativo/imagens/fechar.png"))); // NOI18N
        btnSairCurso.setText("Cancelar");
        btnSairCurso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSairCursoActionPerformed(evt);
            }
        });

        btnSalvarCurso.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        btnSalvarCurso.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sysdance/aplicativo/imagens/salvar.png"))); // NOI18N
        btnSalvarCurso.setText("Salvar");
        btnSalvarCurso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarCursoActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel1.setText("Mês");

        javax.swing.GroupLayout jblIdadeMinimaLayout = new javax.swing.GroupLayout(jblIdadeMinima);
        jblIdadeMinima.setLayout(jblIdadeMinimaLayout);
        jblIdadeMinimaLayout.setHorizontalGroup(
            jblIdadeMinimaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jblIdadeMinimaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jblIdadeMinimaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jblIdadeMinimaLayout.createSequentialGroup()
                        .addComponent(tfNomeCurso)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jblIdadeMinimaLayout.createSequentialGroup()
                        .addGroup(jblIdadeMinimaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jblNomedoCurso)
                            .addGroup(jblIdadeMinimaLayout.createSequentialGroup()
                                .addGroup(jblIdadeMinimaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jblIdadeMinimaCurso)
                                    .addComponent(tfIdadeMinima, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(158, 158, 158)
                                .addGroup(jblIdadeMinimaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jblIdadeMinimaLayout.createSequentialGroup()
                                        .addComponent(tfTempoDoCurso, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel1))
                                    .addComponent(jblTempoCurso))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 98, Short.MAX_VALUE)
                        .addGroup(jblIdadeMinimaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tfValorDoCurso, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jblValorCurso))
                        .addGap(22, 22, 22))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jblIdadeMinimaLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnSairCurso)
                        .addGap(30, 30, 30)
                        .addComponent(btnSalvarCurso, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        jblIdadeMinimaLayout.setVerticalGroup(
            jblIdadeMinimaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jblIdadeMinimaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jblNomedoCurso)
                .addGap(18, 18, 18)
                .addComponent(tfNomeCurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jblIdadeMinimaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jblIdadeMinimaCurso)
                    .addComponent(jblTempoCurso)
                    .addComponent(jblValorCurso))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jblIdadeMinimaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfIdadeMinima, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfTempoDoCurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfValorDoCurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(54, 54, 54)
                .addGroup(jblIdadeMinimaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSairCurso)
                    .addComponent(btnSalvarCurso))
                .addContainerGap(24, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jblIdadeMinima, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jblIdadeMinima, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tfTempoDoCursoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfTempoDoCursoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfTempoDoCursoActionPerformed

    private void btnSairCursoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSairCursoActionPerformed
        // TODO add your handling code here:
        super.fecharJanela();
    }//GEN-LAST:event_btnSairCursoActionPerformed

    private void btnSalvarCursoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarCursoActionPerformed
        // TODO add your handling code here:

        try {

            curso.setNome(tfNomeCurso.getText());
            curso.setIdade(Integer.valueOf(tfIdadeMinima.getText()));
            curso.setTempo(Integer.valueOf(tfTempoDoCurso.getText()));
            curso.setValor(Double.valueOf(tfValorDoCurso.getText()));
            SCurso.scurso.salva(curso);

            fecharJanela();

        } catch (Exception ex) {

            trataException(ex);

    }//GEN-LAST:event_btnSalvarCursoActionPerformed
    }

    private void trataException(Exception e) {
        JOptionPane.showMessageDialog(this, e.getMessage(), "Erro - Dados incorreto!", JOptionPane.ERROR_MESSAGE);

    }

    /**
     * @param args the command line argumentss
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaCurso.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaCurso.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaCurso.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaCurso.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                TelaCurso dialog = new TelaCurso(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnSairCurso;
    private javax.swing.JButton btnSalvarCurso;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jblIdadeMinima;
    private javax.swing.JLabel jblIdadeMinimaCurso;
    private javax.swing.JLabel jblNomedoCurso;
    private javax.swing.JLabel jblTempoCurso;
    private javax.swing.JLabel jblValorCurso;
    private javax.swing.JTextField tfIdadeMinima;
    private javax.swing.JTextField tfNomeCurso;
    private javax.swing.JTextField tfTempoDoCurso;
    private javax.swing.JTextField tfValorDoCurso;
    // End of variables declaration//GEN-END:variables
}
